//
//  WRYLoadImageManager.m
//  BaiSiBuJie
//
//  Created by wry on 16/5/5.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "WRYLoadImageManager.h"
#import "WRYThemeItem.h"
@implementation WRYLoadImageManager

/**
 *  给imageVIew加载图片
 *
 *  @param imageView      需要要加载图片的的ImageView
 *  @param urlStr         图片的URL
 *  @param placeholder    站位图片
 *  @param progressBlock  下载过程中回调
 *  @param completedBlock 下载完成后的回调
 */

+(void)wry_setImageToImageView:(UIImageView*)imageView  WithURL:(NSString *)urlStr placeholderImage:(UIImage *)placeholder progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock
{

    //判断SDWebImage有没有做过缓存,没有就下载;如果做过，就直接获取缓存图片，不需要加载
    UIImage *cacheImage=[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urlStr];
    
    if (cacheImage) {
        //有缓存就设置图片,不再裁剪
        [imageView sd_setImageWithURL:[NSURL URLWithString:urlStr]];

        
//        imageView.image=cacheImage;不能这样赋值,gif图片会出现漏洞.
        //这里优化的不是下载,而是优化裁剪大图,如果缓存已经裁剪的大图,就不要再次裁剪
        
    }else{
        //没有缓存就下载并裁剪
        [imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:placeholder options:SDWebImageRetryFailed progress:progressBlock completed:completedBlock];
        }
}
@end
